package com.matt.controller.web.care;

import com.matt.controller.pad.care.CareBaseController;
import com.matt.domain.care.HLHandoverRecord;
import com.matt.service.care.HLHandoverRecordService;
import com.matt.service.care.po.HLHandoverRecordPO;
import com.starinside.wp.domain.WxUser;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.foundation.vo.BindedBabyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.starinside.wp.foundation.constant.RequestConstant.TICKET;


@RestController
@RequestMapping("/web/record/handover")
@Slf4j
@Api(tags = "护理记录 - 药品交接")
public class WebCareHandoverController extends CareBaseController<HLHandoverRecord, HLHandoverRecordService, HLHandoverRecordPO> {

    @Autowired
    public void setBaseService(HLHandoverRecordService service){
        super.setBaseService(service);
    }

    @ApiOperation(value = "增加一条记录（使用childId）或多个记录（使用childIds）, 响应结果都是数组")
    @PostMapping(produces = "application/json;charset=UTF-8")
    public StatusResponse add(HttpServletRequest req, HttpServletResponse resp,
                              @RequestHeader(TICKET) String ticket, @RequestBody HLHandoverRecordPO param){

        WxUser loginUser = (WxUser) req.getSession().getAttribute("loginUser");
        BindedBabyVO defaultBaby = loginUser.getDefaultBaby();

        param.setChildId(defaultBaby.getId());
        param.setChildIds(null);

        HLHandoverRecord ret = baseService.add(loginUser.getParentId(), defaultBaby, param);

        return StatusResponse.success(ret);

    }

    @ApiOperation(value = "逻辑删除一个对象")
    @DeleteMapping()
    public StatusResponse delete(HttpServletRequest req, HttpServletResponse resp,
                                 @RequestHeader(TICKET) String ticket, String childId, String id ){

        WxUser loginUser = (WxUser) req.getSession().getAttribute("loginUser");
        BindedBabyVO defaultBaby = loginUser.getDefaultBaby();


        baseService.delete(defaultBaby.getAreaId(), loginUser.getParentId(), defaultBaby.getId(), id);

        return StatusResponse.success();
    }
}
